
import Taro, { Component } from '@tarojs/taro'
import {View, Text, Image} from '@tarojs/components'
import { observer, inject } from '@tarojs/mobx'
import {IStoreProps} from '../../store/Stores'

import './buySuccess.scss'
import icon_01 from "../../assets/img/icon_01.png";
import {getStorage, navigateBack, navigateTo, setStorage, showToast} from "../../utils/common";

interface IHomeProps extends IStoreProps {}

@inject("stores")
@observer
class FishBuy extends Component<IHomeProps> {
  state = {
    orderInfo: {}
  }

  componentWillMount () {
    let orderInfo = getStorage('orderInfo')
    // if(Object.keys(orderInfo).length <= 0) { showToast('系统发生错误,请重新下单'); setTimeout(() => {navigateBack()}, 2000) }
    this.setState({ orderInfo })
  }

  link = (url: string) => {
    navigateTo(url)
  }

  render () {
    let {orderInfo} = this.state
    return (
      <View className='pay-success page-bg content-20'>
        <View className='success-header'>
          <Image className='success-header__icon' src={icon_01} />
          <View className='success-header__title'>购买成功</View>
          <View className='success-header__desc'>祝您购物愉快，欢迎下次光临！</View>
        </View>

        <View className='line-common__wrap'>
        <View className='line-common'>
          <View className='line-common__title'>购买数量</View>
          <View className='line-common__con'>{orderInfo.productNum}<Text className='small'>条</Text> </View>
        </View>
        <View className='line-common'>
          <View className='line-common__title'>购买时长</View>
          <View className='line-common__con'>{orderInfo.productDays}<Text className='small'>天</Text> </View>
        </View>
        <View className='line-common'>
          <View className='line-common__title color-orange'>实付金额</View>
          <View className='line-common__con color-orange yuan fw'>{(orderInfo.productPrice || 0).toFixed(2)}</View>
        </View>
        </View>

        <View className='btn-two-wrap'>
          <View className='btn-two-wrap__btn btn-two-wrap__active' onClick={this.link.bind(this, '/pages/mine/fishDetail?id='+orderInfo.orderId)}>查看详情</View>
          <View className='btn-two-wrap__btn' onClick={this.link.bind(this, '/pages/index/index')}>返回首页</View>
        </View>
      </View>
    )
  }
}

export default FishBuy
